﻿#region File Header
//-----------------------------------------------------------------------------
// SibLib
//
// Copyright (C) 2010 Julien Villers
// This program is distributed under the terms of the 
// GNU Lesser General Public License (LGPL).
// See Docs/lgpl.txt and Docs/gpl.txt
//-----------------------------------------------------------------------------
#endregion

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace SibLib.Render
{
    public class Camera
    {
        protected Matrix m_ViewMatrix;
        protected Matrix m_ProjectionMatrix;
        protected Matrix m_WorldMatrix;

        public Matrix ViewMatrix
        {
            get { return m_ViewMatrix; }
        }

        public Matrix ProjectionMatrix
        {
            get { return m_ProjectionMatrix; }
        }

        public Matrix WorldMatrix
        {
            get { return m_WorldMatrix; }
        }

        public Camera()
        {
            m_ViewMatrix = Matrix.Identity;
            m_ProjectionMatrix = Matrix.Identity;
            m_WorldMatrix = Matrix.Identity;
        }

        public void CreateLookAt(Game game, float fov)
        {
            CreateLookAt(game, fov, new Vector3(0.0f, 0.0f, -10000.0f), 10000.0f);
        }

        public void CreateLookAt(Game game, float fov, Vector3 baseCameraPos, float viewDistance)
        {
            Viewport viewport = game.GraphicsDevice.Viewport;
            Matrix.CreatePerspectiveFieldOfView(MathHelper.ToRadians(fov), viewport.Width / (float)viewport.Height, 1.0f, viewDistance, out m_ProjectionMatrix);
            Vector2 screenCenter = new Vector2(viewport.Width / 2.0f, viewport.Height / 2.0f);
            m_ViewMatrix = Matrix.CreateLookAt(baseCameraPos, Vector3.Zero, Vector3.UnitY);
            m_WorldMatrix = Matrix.Identity;

        }
    }
}
